package tsou.cn.glidetest.Util;

import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

import tsou.cn.glidetest.MyApplication;

/**
 * Created by Administrator on 2017/11/21 0021.
 */

public class UIUtils {
    private static Toast toast;

    /**
     * 静态吐司
     *
     * @param context
     * @param text
     */
    public static void showToast(Context context, String text) {
        if (toast == null) {
            toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        }
        toast.setText(text);
        toast.show();
    }

    /**
     * 不需要上下文对象的  静态toast
     */
    public static void showToast(String text) {
        showToast(getContext(), text);
    }

    /**
     * 在子线程里弹出Toast
     *
     * @param text
     */
    public static void showToastInChildThread(Activity getActivity, final String text) {
        getActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(text);
            }
        });
    }

    /**
     * 获取上下文对象
     *
     * @return
     */
    public static Context getContext() {
        return MyApplication.getInstance();
    }
}
